<?php
include_once '../meihe/common.php';
if($islogin2==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
$title='自助续费权限';
include_once './header.php';
$fenzhan_expiry2 = $conf['fenzhan_expiry2']>0?$conf['fenzhan_expiry2']:12;
if($userrow['endtime']>date("Y-m-d")) $endtime = date("Y-m-d", strtotime("+ {$fenzhan_expiry2} months", strtotime($userrow['endtime'])));
else $endtime = date("Y-m-d", strtotime("+ {$fenzhan_expiry2} months"));    
$price=$conf['xfzh'];
if($userrow['power']==1){
   exit("<script language='javascript'>alert('你没有权限使用，无法续费！');window.location.href='./';</script>");
}
?>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                自助续费账号
            </div>
            <div class="card-body">
                <form class="form-horizontal layui-form">
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">当前账号到期时间：<span class="badge badge-danger-lighten">账号剩余额：<?php echo round($userrow['rmb'],2)?>元</span></label>
                      	<input name="endtime1" class="form-control" value="<?php echo $userrow['endtime']?>" disabled/>
                   </div>
                   <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">续费后到期时间：</label>
                       	<input name="endtime" class="form-control" value="<?php echo $endtime?>" disabled/>
                   </div>        
                   <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">续费价格：</label>
                        <input name="need" class="form-control" value="<?php echo $price?> 元"  disabled>
                   </div>           
                    <button type="submit" class="btn btn-block btn-xs btn-outline-success" lay-submit lay-filter="submit_uppower">立即续费</button>
                </form>
            </div>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script type="text/javascript">
layui.use(['form'], function () {
    var form = layui.form;
    form.on('submit(submit_uppower)', function (data) {
        layer.alert('是否要执行当前操作？', {
            icon: 3, btn: ['确定', '取消'], btn1: function (layero, index) {
                uppower();
            }
        });
        return false;
    });
});
function uppower() {
    var endtime = $("select[name='endtime']").val();
    var ii = layer.msg('正在续费中,请稍后...', {icon: 16, time: 10 * 1000});
    $.ajax({
        type: "POST",
        url: "ajax.php?act=xfzhpp",
        data : {endtime:endtime},
        dataType: "json",
        success: function(data) {
            layer.close(ii);
            if (data.code == 0) {
                layer.msg(data.msg, {
                    icon: 6,
                    end: function (layero, index) {
                        window.location.reload();
                    }
                });
            } else if (data.code == 1) {
                layer.msg(data.msg, {
                    icon: 6,
                    end: function (layero, index) {
                        window.location.href = './';
                    }
                });
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        },
        error:function(data){
            layer.msg('服务器错误', {icon: 5});
            return false;
        }
    });
    return false;
};
</script>